package com.jiuqi.abc.model.web;

import com.jiuqi.abc.intf.provider.member.Member;
import com.jiuqi.abc.model.service.ABCDimensionService;
import com.jiuqi.abc.model.service.ABCModelService;
import com.jiuqi.abc.model.vo.*;
import com.jiuqi.np.core.restapi.annotation.PermissionsResourceGroup;
import com.jiuqi.nvwa.sf.anno.Licence;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = {"abc模型成本维度管理"})
@RestController
@RequestMapping("abc/model/dimension")
@PermissionsResourceGroup("abc模型成本维度管理")
@Licence(module="com.jiuqi.abc.modelmanager", point="com.jiuqi.abc.function")
public class ABCDimensionController {
    private static final String STATUS = "status";
    @Autowired
    ABCDimensionService abcDimensionService;

    @Autowired
    ABCModelService abcModelService;

    @ApiOperation("逐级获取 维度")
    @GetMapping("getChildren")
    public Map<String, Object> getChildren(@RequestParam("parentName") String parentName) {
        List<DimensionVo> childrens =  abcDimensionService.getDimensionChildrens(parentName);
        //返回给前端的数据
        HashMap<String, Object> result = new HashMap<>();
        result.put("childrens", childrens);

        return result;
    }

    @ApiOperation("根据 后代维度编码 获取 溯源维度编码路径")
    @GetMapping("getTracePath/{dimName}")
    public Map<String, Object> getTracePath(@PathVariable("dimName") String dimName) {
        List<String> tracePath =  abcDimensionService.getDimensionTracePath(dimName);
        //返回给前端的数据
        HashMap<String, Object> result = new HashMap<>();
        result.put("tracePath", tracePath);

        return result;
    }



    @ApiOperation("根据 模型ID 获取 维度集合")
    @GetMapping("/all/{modelId}")
    public Map<String, Object> getAllDimensionListByModelId(@PathVariable("modelId") String modelId) {
        List<DimBeanVo> allDimBeanVoList = abcModelService.queryModelDimListByModelId(modelId);

        //返回给前端的数据
        HashMap<String, Object> result = new HashMap<>();
        result.put("allDimBeanVoList", allDimBeanVoList);
        result.put(STATUS, "成功");

        return result;
    }


    @ApiOperation("根据类型[分摊维度、成本对象]  获取  维度集合")
    @PostMapping("byDimType/{modelId}/{dimType}")
    public Map<String, Object> getDimensionMemberListByType(@PathVariable("modelId")String modelId,@PathVariable("dimType") int dimType) {
        //dimensionParameterVo 包含属性：String modelId, int type
        List<DimensionVo> dimensionVoList = abcDimensionService.getDimensionMemberListByType(modelId, dimType);


        //返回给前端的数据
        HashMap<String, Object> result = new HashMap<>();
        result.put("tabList", dimensionVoList);
        result.put(STATUS, "成功");

        return result;
    }

    @ApiOperation("根据 维度名称、时期参数、模型ID  获取 维度项集合")
    @PostMapping("member/byDimName")
    public Map<String, Object> getDimensionMemberListByDimName(@RequestBody DimensionParameterVo dimensionParameterVo) {
        List<DimensionMemberVo> memberList = abcDimensionService.getDimensionMemberListByVo(dimensionParameterVo);

        //返回给前端的数据
        HashMap<String, Object> result = new HashMap<>();
        result.put("showList", memberList);
        result.put(STATUS, "成功");

        return result;
    }

    @ApiOperation("根据 维度名称、时期参数  获取 维度项集合 并进行 模糊匹配")
    @PostMapping("member/fuzzyMatch")
    public Map<String, Object> fuzzyMatchDimMembers(@RequestBody DimensionParameterVo dimensionParameterVo) {
        List<Member> matchedDimMemberList = abcDimensionService.fuzzyMatchDimMembers(dimensionParameterVo);

        //返回给前端的数据
        HashMap<String, Object> result = new HashMap<>();
        result.put("matchedDimMemberList", matchedDimMemberList);
        result.put(STATUS, "成功");

        return result;
    }

    @ApiOperation("根据 维度编码 和 维度项编码集合 获取 维度项列表")
    @PostMapping("member/byDimMemberCodes/{dimName}")
    public Map<String, Object> getDimensionMemberListByNameAndCodes(@PathVariable("dimName")String dimName,
                                                             @RequestBody List<String> memberCodes){

        List<Member> memberList = abcDimensionService.getDimensionMemberListByNameAndCodes(dimName, memberCodes);
        //返回给前端的数据
        HashMap<String, Object> result = new HashMap<>();
        result.put("dimMemberList", memberList);
        result.put(STATUS, "成功");

        return result;
    }


}
